/**
 *
 */
package com.bailun91.auth.util;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;


/**
 * @author hero
 * @Description
 * @date 2018年12月7日
 */
public class ShiroUtils {


    public static String sha256(String password, String salt) {
        return new SimpleHash(Constants.hashAlgorithmName, password, salt, Constants.hashIterations).toString();
    }

    public static String sha256(String password) {
        return sha256(password, Constants.SALT);
    }

    public static Subject getSubject() {
        return SecurityUtils.getSubject();
    }

    public static boolean isLogin() {
        return SecurityUtils.getSubject().getPrincipal() != null;
    }

    public static void logout() {
        SecurityUtils.getSubject().logout();
    }

    public static void main(String[] args) {
        System.out.println(sha256("123456", Constants.SALT));
    }
}
